﻿using com.guojin.core.io.message;
using System.Collections;
using System.Collections.Generic;
using com.guojin.mj.net.message.game;
using UnityEngine;
using DG.Tweening;

public class ChapterEndController : MonoBehaviour
{
    private static ChapterEndController instance;

    public static ChapterEndController GetInstance()
    {
        return instance;
    }
    void Awake()
    {
        instance = this;
    }

    public void OnReceviceMsg129(string msg, Message data)
    {
        ChapterInfoRet cir = (ChapterInfoRet) data;

        ChapterEndSetChapterRoomInfo(cir);

        ChapterEndSetChapterUserInfo(cir);

        if (GameRoomModel.GetInstance().existRoom)
        {
            StartCoroutine("send1214");
        }
    }

    IEnumerator send1214()
    {
        yield return new WaitForSeconds(1f);

        if (GameRoomModel.GetInstance().AutoNiu)
        {
            GameData.GetInstance().isClickThisChapter = true;
        }

       MessageManager.GetInstance().SendMsg1214(GameData.GetInstance().locationIndex, GameData.GetInstance().isClickThisChapter); 
    }


    private void ChapterEndSetChapterRoomInfo(ChapterInfoRet cir)
    {
        GameRoomModel.GetInstance().RoomState = 4;
        DownTime.GetInstance().StopDownTime();
        GameRoomPage.GetInstance().SetNoNiuBtn(0);
    }

    public void ChapterEndSetChapterUserInfo(ChapterInfoRet cir)
    {
        //庄不变  已完成不变 
       
        for (int i = 0; i < cir.userChapterInfo.Count; i++)
        {
            if (cir.userChapterInfo[i].LocationIndex == GameData.GetInstance().locationIndex)
            {
                GameRoomPage.GetInstance().SetAud2AndPlay(cir.userChapterInfo[i].CardType);
            }
            Player player = GameRoomModel.GetInstance().playerDic[cir.userChapterInfo[i].LocationIndex];
            player.ShowReady(true);
            player.TotalScore = cir.userChapterInfo[i].TotalScore;
            player.SettleScore = cir.userChapterInfo[i].SettlementScore;
            player.ShowCardBaseCardType(cir.userChapterInfo[i].Cards);
            player.ShowCardDistance(cir.userChapterInfo[i].CardType);
            player.ShowCardPitchBaseCardType(cir.userChapterInfo[i].CardType);
            player.ShowCardType(true, cir.userChapterInfo[i].CardType);
        }     
    }
}
